package com.commAspects.utils;

import java.util.Stack;

public class TimerUtility 
{
	public static Stack stack = new Stack();
	
	public static void addStart(String methodName,String type,long time,String threadName)
	{
		stack.push(new RecordTime(time,methodName,type,threadName));
	}
	
	public static void addEnd(String methodName,String type,long time,String threadName)
	{
		RecordTime recordTime = (RecordTime)stack.peek();
		if(!recordTime.getThreadName().equals(threadName))
		{
			System.out.println("thread mismatch ["+recordTime.getThreadName()+"]["+threadName+"]");
		}
		
		RecordTime recordEndTime = (RecordTime)stack.pop();
		if(recordEndTime != null && recordEndTime.getMethodName().equals(methodName))
		{
			long timeInSec = (time - recordEndTime.getStartTime())/1000;
			//if(timeInSec > 0)
				System.out.println("Method Name : "+recordEndTime.getMethodName()+" Duration : "+timeInSec);
		}
	}
}
